import vector
import seek
#------------------------------------------------------------------------------
# Name: AssaultMarine
# Desc: sterowanie -> kalsa bazowa dla wszystkich zachowan sterujacych
#------------------------------------------------------------------------------


class Steer:
 
    position = vector.Vector(0.0,0.0)
    orientation = vector.Vector(0.0,0.0)
    velocity = vector.Vector(0.0,0.0)
    force = vector.Vector(0.0,0.0)
    
    max_speed = 5.0
    max_force = 10.0
    mass = 1.0
 
    def __init__(self):
        pass
    
 
    def calculate(self, targetPosition):
        pass
    
    def separation(self, neighbors):
      
        steeringForce = vector.Vector(0.0, 0.0)
        
        for neighbor in neighbors:        
            #make sure this agent isn't included in the calculations and that
            #the agent being examined is close enough.
            if(neighbor.steering != self):
                toAgent = self.position.subtract(neighbor.steering.position)
                if (toAgent.length() != 0):
                    toAgent = toAgent.normalize().divide(toAgent.length())
                    steeringForce = steeringForce.add(toAgent)
        
        return steeringForce
 
    def aligment(self, neighbors):
        
        centerOfMass = vector.Vector(0.0, 0.0)
        steeringForce = vector.Vector(0.0, 0.0)
        
        #first find the center of mass of all the agents
        #iterate through the neighbors and sum up all the position vectors
        for neighbor in neighbors:
            if(neighbor.steering != self):
                centerOfMass.add(vector.Vector(neighbor.rect.centerx, neighbor.rect.centery))


        if (len(neighbors) - 1 > 0):
            #the center of mass is the average of the sum of positions
            centerOfMass.divide(len(neighbors) - 1)
            #now seek toward that position
            steeringForce = seek.Seek().calculate(centerOfMass)

        return steeringForce
    
    
    def cohesion(self, neighbors):
        
        centerOfMass = vector.Vector(0.0, 0.0)
        steeringForce = vector.Vector(0.0, 0.0)
        
        #first find the center of mass of all the agents
        #iterate through the neighbors and sum up all the position vectors
        for neighbor in neighbors:
            #make sure *this* agent isn't included in the calculations and that
            #the agent being examined is a neighbor
            if(neighbor.steering != self):
                centerOfMass.add(neighbor.steering.position)


        if (len(neighbors) - 1 > 0):
            #the center of mass is the average of the sum of positions
            centerOfMass.divide(len(neighbors) - 1)
            #now seek toward that position
            steeringForce = seek.Seek().calculate(centerOfMass)


        return steeringForce





    

    
    